home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 2.4 KB | 85 lines | [TEXT/GEOL] |
- Item 1762206 24-Jan-90 15:43
-
- From: AUST0134 Jam Software Sydney,IVR
-
- To: DAWSON.M Dawson, Mark
- MACAPP.TECH$ MacApp Technical
-
- Sub: Re dynamic menus
-
- Mark,
-
- >What I'm not sure about is how to build a menu, informing MacApp that there's
- >a new item and what its command number is (so MacApp will fill in the
- >'itsChoice' field of my DoChoice() method with a number that I know how to
- >deal with).
-
- You are confusing the DoChoice chain with the Command chain. The DoChoice
- chain is traversed on clicking in a control. The command chain is traversed
- when a menu item is selected or on a keystroke.
-
- When MacApp handles a menu command which does not have an associated command
- number defined, (as in a menu with a dynamic number of items) it will return a
- negative command number. Your DoMenuCommand can convert this number to a menu
- and item number using CmdToMenuItem, and handle it appropriately.
- MacApp does not need to be informed specifically if you add or remove items,
- just ensure that your DoSetupMenus and DoMenuCommand can handle all the items
- you have on the menu.
-
- {An example of using dynamic menus}
- PROCEDURE TMyView.RebuildMenus; OVERRIDE;
- VAR
- count,i:INTEGER;
- aStr: Str255;
- myMenu: MenuHandle;
- BEGIN
- myMenu := GetMHandle( kMyMenuID );
- count := CountMItems( myMenu );
- FOR i := count DOWNTO 1 DO
- DelMenuItem( myMenu, i );
- EnableItem( myMenu, 0 );
- { rebuild the dynamic menu from my own list }
- FOR i := 1 TO fFiles.fSize DO BEGIN
- aStr := TNameObject(fFiles.At(i)).fName;
- AppendMenu( myMenu, aStr );
- END;
- END;
-
- PROCEDURE TMyView.DoSetupMenus; OVERRIDE;
- VAR
- count,i:INTEGER;
- aStr: Str255;
- myMenu: MenuHandle;
- BEGIN
- INHERITED DoSetupMenus;
- { we will enable all the items on the dynamic menu }
- myMenu := GetMHandle( kMyMenuID );
- count := CountMItems( myMenu );
- FOR i := 1 TO count DO BEGIN
- EnableItem( fileMenu, i );
- END;
- END;
-
- FUNCTION TMyView.DoMenuCommand(aCmdNumber: CmdNumber): TCommand; OVERRIDE;
- VAR
- menu, item: INTEGER;
- BEGIN
- DoMenuCommand := gNoChanges;
- CmdToMenuItem(aCmdNumber, menu, item);
- IF menu = kMyMenuID THEN BEGIN
- CASE item OF
- …
- {Do your thing}
- …
- END;
- END ELSE
- DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
- END;
-
- With luck this will be of assistance.
-
- Tseung Cheung
- JAM Software Pty Ltd
- AUST0134
-
-